package org.biodas.jdas.client.adapters.features;

import org.biodas.jdas.exceptions.ValidationException;
import org.biodas.jdas.schema.features.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: ljgarcia
 * Date: 22-Feb-2011
 * Time: 11:07:30
 * To change this template use File | Settings | File Templates.
 */
public class FeatureAdapter extends FEATURE {
    //Attributes
    private String id;
    private String label;
    //Typed Elements
    private TYPE type;
    private METHOD method;
    private List<LINK> links;
    private List<TARGET> targets;
    private List<PARENT> parents;
    private List<PART> parts;
    //Simple elements
    private int start, end;
    private String score, orientation, phase;
    private List<String> notes;
    /**
     * New adapter for a feature.
     */
    public FeatureAdapter() throws ValidationException {
        this.links = new ArrayList<LINK>();
        this.targets = new ArrayList<TARGET>();
        this.parents = new ArrayList<PARENT>();
        this.parts = new ArrayList<PART>();
        this.start = this.end = 0;
        this.score = "-";
        this.orientation = "0";
        this.phase = "-";
        this.notes = new ArrayList<String>();
        this.init();
    }
    /**
     * Init all attributes from the adaptee.
     * @throws ValidationException
     */
    private void init() throws ValidationException {
//        try {
//            List<Object> list = this.feature.getTYPEOrMETHODOrSTART();
//
//            for (Object obj: list) {
//                if (obj instanceof TYPE) {
//                    this.type = (TYPE)obj;
//                } else if (obj instanceof METHOD) {
//                    this.method = (METHOD)obj;
//                } else if (obj instanceof LINK) {
//                    this.links.add((LINK)obj);
//                } else if (obj instanceof TARGET) {
//                    this.targets.add((TARGET)obj);
//                } else if (obj instanceof PARENT) {
//                    this.parents.add((PARENT)obj);
//                } else if (obj instanceof PART) {
//                    this.parts.add((PART)obj);
//                } else if (obj instanceof JAXBElement) {
//                    JAXBElement elem = (JAXBElement)obj;
//                    if (elem.getName().getLocalPart().equals(FeatureSimpleElements.START.getValue())) {
//                        try {
//                            this.start = Integer.parseInt(elem.getValue().toString());
//                        } catch (Exception e) {
//                            this.start = 0;
//                        }
//                    } else if (elem.getName().getLocalPart().equals(FeatureSimpleElements.END.getValue())) {
//                        try {
//                            this.end = Integer.parseInt(elem.getValue().toString());
//                        } catch (Exception e) {
//                            this.end = 0;
//                        }
//                    } else if (        	elem.getName().getLocalPart().equals(FeatureSimpleElements.SCORE.getValue())) {
//                        this.score = elem.getValue().toString(); 
//                    } else if (elem.getName().getLocalPart().equals(FeatureSimpleElements.ORIENTATION.getValue())) {
//                        this.orientation = elem.getValue().toString(); 
//                    } else if (elem.getName().getLocalPart().equals(FeatureSimpleElements.PHASE.getValue())) {
//                        this.phase = elem.getValue().toString(); 
//                    } else if (elem.getName().getLocalPart().equals(FeatureSimpleElements.NOTE.getValue())) {
//                        this.notes.add(elem.getValue().toString());
//                    }
//                }
//            }
//        } catch (Exception e) {
//            throw new ValidationException("There was a problem adapting the feature " + this.id + " (" + e.getMessage() + ")");
//        }
//        if (this.type == null) {
//            throw new ValidationException("No type was found for this feature " + this.id);
//        }
//        if (this.method == null) {
//            throw new ValidationException("No method was found for this feature " + this.id);
//        }
    }

    /**
     * Returns the feature id.
     * @return
     */
    public String getId() {
        return this.id;
    }

    /**
     * Returns the feature label.
     * @return
     */
    public String getLabel() {
        return this.label;
    }
     /** Returns the feature type.
     * @return
     */
    public TYPE getType() {
        return this.type;
    }
    /** Returns the feature method.
     * @return
     */
    public METHOD getMethod() {
        return this.method;
    }
    /** Returns all links for this feature.
     * @return
     */
    public List<LINK> getLinks() {
        return this.links;
    }

    /**
     * Returns all targets for this feature.
     * @return
     */
    public List<TARGET> getTargets() {
        return this.targets;
    }

    /**
     * Returns all parents for this feature.
     * @return
     */
    public List<PARENT> getParents() {
        return this.parents;
    }

    /**
     * Retunrs all parts for this feature.
     * @return
     */
    public List<PART> getParts() {
        return this.parts;
    }
    /** Returns the start position for this feature.
     * @return
     */
    public int getStart() {
        return this.start;
    }
    /** Returns the end position for this feature.
     * Although more than one is possible when translate from RelaxNG to XSD, it should be
     * exactly one.
     * @return
     * @throws uk.ac.ebi.das.jdas.exceptions.ValidationException
     */
    public int getEnd() throws ValidationException {
        return this.end;
    }
    /** Returns the score for this feature.
     * @return
     */
    public String getScore() {
        return this.score;
    }
    /** Returns the orientation for this feature.
     * @return
     */
    public String getOrientation() {
        return this.orientation;
    }
    /** Returns the phase for this feature.
     * @return
     */
    public String getPhase() {
        return this.phase;
    }
    /** Returns the notes for this feature.
     * @return
     */
    public List<String> getNotes() {
        return this.notes;
    }
    //Setters
    public void setId(String id) {
        this.id = id;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public void setType(TYPE type) {
        this.type = type;
    }

    public void setMethod(METHOD method) {
        this.method = method;
    }

    public void setLinks(List<LINK> links) {
        this.links = links;
    }

    public void setTargets(List<TARGET> targets) {
        this.targets = targets;
    }

    public void setParents(List<PARENT> parents) {
        this.parents = parents;
    }

    public void setParts(List<PART> parts) {
        this.parts = parts;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public void setEnd(int end) {
        this.end = end;
    }

    public void setScore(String score) {
        this.score = score;
    }

    public void setOrientation(String orientation) {
        this.orientation = orientation;
    }

    public void setPhase(String phase) {
        this.phase = phase;
    }

    public void setNotes(List<String> notes) {
        this.notes = notes;
    }
}
